import {
  getClassInfoList,
  getClassLevelList,
  getStudentList,
  getSubjectList,
  addClassInfo,
  getClassInfoEdit,
  updateClassInfo,
  removeClassStuRef,
  getNeedStudentList,
  getClassTypeList,
} from  '../../../service/api';
import { message } from 'antd';
export default {
  namespace: 'classInfo3',
  state: {
    classInfoList: {
      total: 0,
      list: [],
    },
    classLevelList: [],
    similarStudentList: [],
    subjectList: [],
    addClassResponse: null,
    classInfo: {},
    updateClassResponse: null,
    removeClassResponse: null,
    needStudent: [],
    classTypeList: [],
  },
  effects: {
    *getClassTypeList({ payload }, { call, put }) {
      const response = yield call(getClassTypeList, payload);
      yield put({
        type: 'r_getClassTypeList',
        payload: response,
      });
    },
    *getClassInfoPage({ payload }, { call, put }) {
      const response = yield call(getClassInfoList, payload);
      yield put({
        type: 'r_classInfoList',
        payload: response,
      });
    },
    *getClassLevel({ payload }, { call, put }) {
      const response = yield call(getClassLevelList, payload);
      yield put({
        type: 'r_classLevel',
        payload: response,
      });
    },
    *getStudentList({ payload }, { call, put }) {
      const response = yield call(getStudentList, payload);
      yield put({
        type: 'r_studentList',
        payload: response,
      });
    },
    *getNeedStudentList({ payload }, { call, put }) {
      const response = yield call(getNeedStudentList, payload);
      yield put({
        type: 'r_getNeedStudentList',
        payload: response,
      });
    },
    *getSubjectList({ payload }, { call, put }) {
      const response = yield call(getSubjectList, payload);
      yield put({
        type: 'r_subjectList',
        payload: response,
      });
    },
    *addClassInfo({ payload }, { call, put }) {
      const response = yield call(addClassInfo, payload);
      yield put({
        type: 'r_addClassInfo',
        payload: response,
      });
    },
    *getClassInfo({ payload }, { call, put }) {
      const response = yield call(getClassInfoEdit, payload);
      yield put({
        type: 'r_getClassInfoEdit',
        payload: response,
      });
    },
    *updateClassInfo({ payload }, { call, put }) {
      const response = yield call(updateClassInfo, payload);
      yield put({
        type: 'r_updateClassInfo',
        payload: response,
      });
    },
    *removeClassInfo({ payload }, { call, put }) {
      const response = yield call(removeClassStuRef, payload);
      yield put({
        type: 'r_removeClassInfo',
        payload: response,
      });
    },
  },

  reducers: {
    r_getClassTypeList(state, action) {
      return {
        ...state,
        classTypeList: action.payload.data,
      };
    },
    r_classInfoList(state, action) {
      return {
        ...state,
        classInfoList: action.payload.data,
      };
    },
    r_classLevel(state, action) {
      return {
        ...state,
        classLevelList: action.payload.data,
      };
    },
    r_studentList(state, action) {
      return {
        ...state,
        similarStudentList: action.payload.data,
      };
    },
    r_subjectList(state, action) {
      return {
        ...state,
        subjectList: action.payload.data,
      };
    },
    r_getClassInfoEdit(state, action) {
      return {
        ...state,
        classInfo: action.payload.data,
      };
    },
    r_updateClassInfo(state, action) {
      return {
        ...state,
        updateClassResponse: action.payload,
      };
    },
    r_removeClassInfo(state, action) {
      return {
        ...state,
        removeClassResponse: action.payload,
      };
    },
    r_addClassInfo(state, action) {
      return {
        ...state,
        addClassResponse: action.payload,
      };
    },
    r_getNeedStudentList(state, action) {
      state.needStudent = action.payload.data;
      return {
        ...state,
      };
    },
  },
};
